//
//  ChoiceBuID.m
//  DMGME
//
//  Created by ihope99 on 15/9/2.
//  Copyright (c) 2015年 GYP. All rights reserved.
//

#import "ChoiceBuIDView.h"

@implementation ChoiceBuIDView

- (id)initWithFrame:(CGRect)frame withNum:(int)num
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        
        UILabel *choiceLable = [[UILabel alloc] init];
        choiceLable.frame = CGRectMake(10, 15, 200, 13);
        choiceLable.text = @"选择该用户的身份";
        choiceLable.textAlignment = NSTextAlignmentLeft;
        choiceLable.font = [UIFont systemFontOfSize:14];
        [self addSubview:choiceLable];
        
        NSArray *titleName;
        
        if (num == 1) {
            titleName = @[@"市代理",@"县代理",@"经销商"];
        }else if (num == 2){
            titleName = @[@"县代理",@"经销商"];
        }else if (num == 3){
            titleName = @[@"经销商"];
        }
        CGFloat bwnH = 30;
        CGFloat bwnw = 70;
            int m = 20;
        for (int i = 0; i <= 3 - num; i++) {
            _btn = [UIButton buttonWithType:UIButtonTypeCustom];
             _btn.tag = m ++;
            [_btn setTitle:titleName[i] forState:UIControlStateNormal];
            [_btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
          
            _btn.layer.borderColor = [[UIColor grayColor]CGColor];
            _btn.layer.borderWidth = 0.5;
            _btn.frame = CGRectMake(15 + ((bwnw + 10)*i), 40, bwnw, bwnH);
            [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            _btn.titleLabel.font = [UIFont systemFontOfSize:13];
            [self addSubview:_btn];
          }
        
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = [UIColor grayColor];
        lineView.frame = CGRectMake(0, 85, KWidth, 1);
        [self addSubview:lineView];
        
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame = CGRectMake(0, CGRectGetMaxY(lineView.frame), 260, 35);
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:_cancelBtn];
        if(num == 3)
        {
            _btn.frame = CGRectMake(self.frame.size.width/2-30, bwnw-25, 60, bwnH);
        }
    }
    return self;
}
- (void)btnClick:(UIButton *)sender
{
        [_delegete prensetChoiceBuIDViewClick:sender.tag];
}
@end
